//
//  TableViewCell.m
//  Trip
//
//  Created by dllo on 15/7/17.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "TravelPushTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation TravelPushTableViewCell

- (void)dealloc
{
    [_day release];
    [_name_zh_cn release];
    [_entry_name release];
    [_descrip release];
    [_titleView release];
    [_url release];
    [_comment release];
    [super dealloc];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCell];
    }
    return self;
}

- (void)createCell
{
    self.titleView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.titleView];
    self.name_zh_cn = [[UILabel alloc] init];
    [self.contentView addSubview:self.name_zh_cn];
    self.url = [[UIImageView alloc] init];
    [self.contentView addSubview:self.url];
    self.descrip = [[UILabel alloc] init];
    [self.contentView addSubview:self.descrip];
    self.comment = [[UILabel alloc] init];
    [self.contentView addSubview:self.comment];
    self.contentView.backgroundColor = [UIColor colorWithRed:231 / 255.0 green:237 / 255.0 blue:241 / 255.0 alpha:1];
    [self.titleView release];
    [self.name_zh_cn release];
    [self.url release];
    [self.descrip release];
    
}
- (void)setTravelNotesAll:(TravelNotesAll *)travelNotesAll
{
    if (travelNotesAll.entry_type != nil && ![travelNotesAll.entry_type isEqual:[NSNull null]]) {
        self.titleView.frame = CGRectMake(15, 10, 30, 30);
        self.titleView.backgroundColor = [UIColor whiteColor];
        self.titleView.layer.borderColor = [UIColor grayColor].CGColor;
        self.titleView.backgroundColor = [UIColor clearColor];
        self.titleView.image = [UIImage imageNamed:@"NodeIconCustom48"];
        self.name_zh_cn.frame = CGRectMake(60, 15, 200, 25);
        self.name_zh_cn.text = travelNotesAll.entry_name;
    }
    
    [self.url setImageWithURL:[NSURL URLWithString:travelNotesAll.url] placeholderImage:nil];
    
    // 有title
    if (travelNotesAll.entry_type != nil && ![travelNotesAll.entry_type isEqual:[NSNull null]]) {
        // 有图片
        if (travelNotesAll.url != nil && ![travelNotesAll.url isEqual:[NSNull null]]) {
            self.url.frame = CGRectMake(10, 60, self.frame.size.width - 20, (self.frame.size.width - 20) * (travelNotesAll.image_height / (CGFloat)travelNotesAll.image_width));
            [self.url setImageWithURL:[NSURL URLWithString:travelNotesAll.url] placeholderImage:[UIImage imageNamed:@"place_holder.jpg"]];
            
            if (travelNotesAll.descrip != nil && ![travelNotesAll.descrip isEqual:[NSNull null]]) {
                self.descrip.frame = CGRectMake(10, (self.url.frame.origin.y + (self.frame.size.width - 20) * (travelNotesAll.image_height / (CGFloat)travelNotesAll.image_width) + 10), self.frame.size.width - 20, 30);
                self.descrip.font = [UIFont systemFontOfSize:15];
                self.descrip.text = travelNotesAll.descrip;
                self.descrip.numberOfLines = 1000;
                [self.descrip sizeToFit];
            }
        } else {
            if (travelNotesAll.descrip != nil && ![travelNotesAll.descrip isEqual:[NSNull null]]) {
                self.descrip.frame = CGRectMake(10, 60, self.frame.size.width - 20, 30);
                
                self.descrip.font = [UIFont systemFontOfSize:15];
                self.descrip.text = travelNotesAll.descrip;
                self.descrip.numberOfLines = 1000;
                [self.descrip sizeToFit];
            }
        }
    } else if (travelNotesAll.entry_type == nil || [travelNotesAll.entry_type isEqual:[NSNull null]]) { // 无title
        // 有图
        if (travelNotesAll.url != nil && ![travelNotesAll.url isEqual:[NSNull null]]) {
            self.url.frame = CGRectMake(10, 10, self.frame.size.width - 20, (self.frame.size.width - 20) * (travelNotesAll.image_height / (CGFloat)travelNotesAll.image_width));
            [self.url setImageWithURL:[NSURL URLWithString:travelNotesAll.url] placeholderImage:[UIImage imageNamed:@"place_holder.jpg"]];
            
            if (travelNotesAll.descrip != nil && ![travelNotesAll.descrip isEqual:[NSNull null]]) {
                
                self.descrip.frame = CGRectMake(10, self.url.frame.origin.y + (self.frame.size.width - 20) * (travelNotesAll.image_height / (CGFloat)travelNotesAll.image_width) + 10, self.frame.size.width - 20, 30);
                self.descrip.font = [UIFont systemFontOfSize:15];
                self.descrip.text = travelNotesAll.descrip;
                self.descrip.numberOfLines = 1000;
                [self.descrip sizeToFit];
            }
            
        } else {
            // 无图
            if (travelNotesAll.descrip != nil && ![travelNotesAll.descrip isEqual:[NSNull null]]) {
                self.descrip.frame = CGRectMake(10, 10, self.frame.size.width - 20, 30);
                self.descrip.font = [UIFont systemFontOfSize:15];
                self.descrip.text = travelNotesAll.descrip;
                self.descrip.numberOfLines = 1000;
                [self.descrip sizeToFit];
                
            }
        }
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

